#!/bin/bash
#define Etcdctl Env
#manifest: zsp
#date: 20190618


export ETCDCTL_API=3
export ETCDCTL_CACERT=/etc/kubernetes/pki/etcd/ca.pem
export ETCDCTL_CERT=/etc/kubernetes/pki/etcd/etcd-client.pem
export ETCDCTL_KEY=/etc/kubernetes/pki/etcd/etcd-client-key.pem

#基于k8s下监控etcd
function kmoniter-etcd()
{

case $1 in 

 
"etcd-status")
	for i in $(kubectl  get nodes -owide |grep "master"|awk '{print $6}');do etcdctl --endpoints=https://"$i":2379 endpoint status -w table ;done
;;

"etcd-health")
	for i in $(kubectl  get nodes -owide |grep "master"|awk '{print $6}');do etcdctl --endpoints=https://"$i":2379 endpoint health ;done
;;

"etcd-member")
       
	for i in $(kubectl  get nodes -owide |grep "master"|awk '{print $6}');do etcdctl --endpoints=https://"$i":2379 member list -w table && [ $? -eq 0 ] && break ;done
;;

*)
       
 echo "    Usage:
        kmointer-etcd flags:

        kmointer-etcd   etcd-status|etcd-health|etcd-member"
;;
esac
}

